//
//  DMTools.h
//  DaMaoMall
//
//  Created by HXHL-wally on 16/7/21.
//  Copyright © 2016年 daMao-wally. All rights reserved.
//

#import <Foundation/Foundation.h>

// AFH 框架封装
#import "AFNetworking.h"
typedef void (^successBlockAFH)(id responseObject);
typedef void (^failureBlockAFH)(NSError *error);

#import "AppDelegate.h"
// 弹框框架
//#import "MBProgressHUD.h"
//#import "JSONKit.h"
// 数据库框架
//#import "FMDB.h"
//#import "NSString+Base64Str.h"
// ASI框架
//#import "ASIHTTPRequest.h"
//#import "ASIFormDataRequest.h"
//#import "ASINetworkQueue.h"
// 是否有网络框架
//#import "Reachability.h"
// SDWebImage 框架
#import "UIImageView+WebCache.h"
// 刷新
//#import "MJRefresh.h"
#import "MJExtension.h"

@interface DMTools : NSObject
// 单利
DEFINE_SINGLETON_FOR_HEADER(DMTools)

//获取Appdelegate 指针
+ (AppDelegate *)appDelegate;

//jsonkit 解析json格式
//+ (NSDictionary *)JSonFromString:(NSString*)result;

//显示指示器
+ (void)showProgress:(UIView *) view;
#pragma mark -    修改
// gif 格式动画显示。 提交动画
//+ (void)showGifImageProgress:(UIView *)view;
#pragma mark -    修改
// 加载当前页面 gif格式动画显示。
//+ (void)showLoadingGifImageProgress:(UIView *)view;
//显示指示器和文字
+ (void)showProgress:(UIView *) view showText:(NSString*)text;

//显示指示器文字
+ (void) showTips:(NSString *)text toView:(UIView *)view;

//显示成功标识指示器和文字以及自定义图片
+ (void)showSuccessTips:(NSString *)text image:(UIImage *)image toView:(UIView *)view;

//显示失败标识指示器和文字
+ (void)showErrorTips:(NSString *)text toView:(UIView *)view;

//隐藏指示器
+ (void)hideProgress:(UIView *)view;

//将字典、数组转换成json串
+(NSString *)stringFromObject:(id)obj;

//将json串反解析
//+(id)objectFromString:(NSString *)str;

//获取uuid
-(NSString *)gen_uuid;

//判断当前时间和过去时间的时间差
- (NSString *)intervalSinceNow:(NSString *) theDate;

//将工程目录文件移动到沙河目录Documnet下
+(void)moveFileToDocument:(NSString *)name andType:(NSString *)type;

//Label自适应大小
+(CGRect )autoSizeOfWidget:(UILabel *)widget andSize:(CGSize)size andtextFont:(CGFloat )sizefont;

//计算文字宽和长
+(CGRect )autoSizeOftext:(NSString *)text andSize:(CGSize)size andtextFont:(CGFloat)sizefont;

//图片无损拉伸
+(UIImage *)stretchableImag:(UIImage *)image;

//获取数据库指针
//+(FMDatabase*)getDb;

//GET 请求 获取数据
//+ (ASIHTTPRequest*)getRequestWithDict:(NSDictionary *)dict API:(NSString *)api;

//POST 请求 获取数据
//+ (ASIFormDataRequest*)postRequestWithDict:(NSDictionary *)dict API:(NSString *)api;

//POST 请求 获取数据(测试地址)
//+ (ASIFormDataRequest*)textpostRequestWithDict:(NSDictionary *)dict API:(NSString *)api;

//POST 请求 上传文件
//+ (ASIFormDataRequest*)postRequestWithDict:(NSDictionary *)dict API:(NSString *)api  fileName:(NSString *)filename  fileData:(NSData *)data;

//判断有无网络
//+ (BOOL)NetworkReachable;

//计算缓存
-(void)CalculateTheCache:(UILabel *)label;

//清理缓存
-(void)clearTheCache:(UILabel *)label;

//创建cell的分割线
-(UIView *)createSeparatorLineWithRect:(CGRect)rect;

//打电话
+(void)MakeAPhoneCall;

//编辑字符串颜色，大小
+(NSMutableAttributedString *)getAcolorfulStringWithTextArray:(NSArray *)array Color:(UIColor *)color Font:(UIFont *)font AllText:(NSString *)allText;
// 显示某个字符 颜色
+(NSMutableAttributedString *)getAcolorfulStringWithText1:(NSString *)text1 Color1:(UIColor *)color1 Font1:(UIFont *)font1 Text2:(NSString *)text2 Color2:(UIColor *)color2 Font2:(UIFont *)font2 AllText:(NSString *)allText;

//验证手机号
+(BOOL)chickIphoneNumberRight:(NSString *)str;
// ASI 网络框架，包含 utyp = @“2”
//+ (ASIFormDataRequest*)postRequestWithDict:(NSDictionary *)dict API:(NSString *)api data:(NSData *)data;

//从数据库获取数据
//+ (NSMutableArray *)getArrayWithKey:(NSString *)key table:(NSString *)table;

/**
 url : 请求的地址
 parameters: 请求参数
 success: 请求成功的回调
 failure: 请求失败的回调
 */
//+ (void)postWithUrl:(NSString *)url  parameters:(NSDictionary *)parameters  success:(successBlockAFH)success  failure:(failureBlockAFH)failure;


//+ (void)postWithHeaderWithUrl:(NSString *)url  parameters:(NSDictionary *)parameters  success:(successBlockAFH)success  failure:(failureBlockAFH)failure;



/**
 url : 请求的地址
 parameters: 请求参数
 success: 请求成功的回调
 failure: 请求失败的回调
 */
//+ (void)getWithUrl:(NSString *)url  parameters:(NSDictionary *)parameters  success:(successBlockAFH)success  failure:(failureBlockAFH)failure;


+ (CGSize )autolayoutSize :(UILabel *)lable;

#pragma mark - 设置 获取验证码 按钮60s不能点击

//设置 获取验证码 按钮60s不能点击
+(void)startTime:(UIButton *)button;

#pragma mark - 偏好
//偏好  保存数据
+ (void)saveValueToUserDefaults:(id)value andKey:(NSString *)key;

#pragma mark - 把字典转化成json串
+(NSString*)dictionaryToJson:(NSDictionary *)dict;

@end
